package com.cat.chapter049;

/**
 * @author cat
 * @description https://leetcode.cn/problems/longest-substring-without-repeating-characters/
 * @create 2025/7/18 19:58
 * @since JDK17
 */

public class Solution02 {
    public int lengthOfLongestSubstring(String s) {
        char[] array = s.toCharArray();
        int n = array.length, l = 0, r = 0, ans = 0;
        int[] h = new int[128];
        for (int i = 0; i < n; i++) {
            int path = ((int) array[i]);
            h[path]++;
            while (h[path] != 1) {
                h[((int) array[l++])]--;
            }
            ans = Math.max(ans, r - l + 1);
        }
        return ans;
    }
}
